/*
  CoveWhsFs
  Copyright (C) 2011 Alex Piskarev  
  http://code.google.com/p/covewhsfs/
  
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option) any
later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "servicei.h"
#include "fileinfo.h"

VOID
DispatchUserFsRequest(
	HANDLE			Handle,
	PEVENT_CONTEXT	EventContext,
	PDOKAN_INSTANCE	DokanInstance)
{
	PEVENT_INFORMATION	eventInfo;
	DOKAN_FILE_INFO		fileInfo;
	PDOKAN_OPEN_INFO	openInfo;
	ULONG	eventInfoLength;
	int		status = STATUS_NOT_IMPLEMENTED;
	ULONG	length = 0;

	eventInfoLength = sizeof(EVENT_INFORMATION) - 8 + EventContext->Fsctl.OutBufferLength;
    
	CheckFileName(EventContext->Security.FileName);

	eventInfo = DispatchCommon(EventContext, eventInfoLength, DokanInstance, &fileInfo, &openInfo);
	
    length = EventContext->Fsctl.OutBufferLength;

	if (DokanInstance->DokanOperations->Fsctl) {
		status = DokanInstance->DokanOperations->Fsctl(
					EventContext->Fsctl.FsControlCode,
					EventContext->Fsctl.InBufferLength,
					&EventContext->Fsctl.InBuffer,
					&length,
					&eventInfo->Buffer,
					&fileInfo);
	}

    eventInfo->BufferLength = length;
    eventInfo->Status = status;
	
	SendEventInformation(Handle, eventInfo, eventInfoLength, DokanInstance);
	free(eventInfo);
}
